package com.example.demo.listener;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.common.Func;
import com.example.demo.listener.event.SysLogEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class SysLogListener {

    @Async("sendEmailAsync")
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) throws InterruptedException {
        JSONObject jsLog = (JSONObject) event.getSource();
        Thread currentThread = Thread.currentThread();
        long id = currentThread.getId();
        String name = currentThread.getName();

        // 将日志信息保存到数据库...
        Func.print("id:" + id + "，text:" + jsLog + "，name:" + name);
        Thread.sleep(10000);
    }
}
